#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/configfs.h>
#include <linux/kernel.h>
#include <linux/kobject.h>
#include <linux/device.h>
#include <stdio.h>


static int my_match(struct device *dev, struct device_driver *drv){
    printk("my_match\n");
    return strcmp(dev_name(dev), drv->name);
}

static int myprobe(struct device *dev){
    
    struct device_driver *drv = dev->driver;
    printk("my_probe\n");
    if(!drv->probe){
        drv->probe(dev);
    }
    return 0;
}

static struct bus_type mybus={
    .name = "mybus",
    .dev_groups = NULL,
    .match = my_match,
    .probe = myprobe,
    .uevent = NULL,
    .pm = NULL,
    .bus_groups = NULL,
   
};
static    struct kobject *mykobj ;
static    struct kobj_type myktype;
static    struct kset *mykset;
 

static int __init mybus_init(void){
    int ret;

    ret = bus_register(&mybus);
    if(ret){
        // printk("bus_register error\n");
        return -1;
    }
    // printk("bus_register success\n");
    mykset = kset_create_and_add("mykset", NULL, NULL);
   
    mykobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
    kobject_init(mykobj, &myktype);
    // ret = kobject_init_and_add(mykobj,&myktype, NULL, "mykobj");
    // ret = kobject_init_and_add(mykobj, &myktype, NULL, "%s","mykobj");
    ret = kobject_uevent(mykobj, KOBJ_CHANGE);
    return 0;
}

static void __exit mybus_exit(void){
    bus_unregister(&mybus);
    printk("bus_unregister success\n");
    // kobject_del(mykobj);
    kobject_put(mykobj);
    kset_unregister(mykset);
}

MODULE_AUTHOR("WLZ");
MODULE_LICENSE("GPL");
module_init(mybus_init);
module_exit(mybus_exit);